﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InfoExpress.WinApp.Utils;

namespace InfoExpress.HIV.WinApp.Utils
{
  internal static class MainFormUtils
  {
    private static FrmMain _frmMain = null;
    
    /// <summary>
    /// Initialize Main form utils
    /// </summary>
    /// <param name="frmMain"></param>
    public static void InitializeUtils(FrmMain frmMain)
    {
      _frmMain = frmMain;
    }

    /// <summary>
    /// Start progress bar of Main form.
    /// </summary>
    public static void StartProgress()
    {
      _frmMain.StartProgress();
    }

    /// <summary>
    /// Stop progress bar of Main form.
    /// </summary>
    public static void StopProgress()
    {
      _frmMain.StopProgress();
    }

    /// <summary>
    /// Set status of Main form.
    /// </summary>
    /// <param name="status"></param>
    public static string StatusText
    {
      get { return _frmMain.StatusText; }
      set { _frmMain.StatusText = value; }
    }

    /// <summary>
    /// Set status of Main form
    /// </summary>
    /// <param name="status"></param>
    public static ApplicationStatus Status
    {
      get { return _frmMain.Status; }
      set { _frmMain.Status = value; }
    }

    /// <summary>
    /// Set default status of Main form.
    /// </summary>
    public static void SetDefaultStatus()
    {
      _frmMain.StatusText = Constants.StatusDefault;
      if (_frmMain.Status != ApplicationStatus.Busy)
        _frmMain.Status = ApplicationStatus.Ready;
    }

    /// <summary>
    /// Set customized busy status of Main form.
    /// </summary>
    public static void SetBusyStatus(string status)
    {
      _frmMain.StatusText = status;
      _frmMain.Status = ApplicationStatus.Busy;
    }

    /// <summary>
    /// Set customized done status of Main form.
    /// </summary>
    public static void SetDoneStatus(string status)
    {
      _frmMain.StatusText = status;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set loading status of Main form.
    /// </summary>
    public static void SetLoadingStatus()
    {
      _frmMain.StatusText = Constants.StatusLoad;
      _frmMain.Status = ApplicationStatus.Busy;
    }

    /// <summary>
    /// Set loaded successfully status of Main form.
    /// </summary>
    public static void SetLoadedStatus()
    {
      _frmMain.StatusText = Constants.StatusLoaded;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set loaded failed status of Main form.
    /// </summary>
    public static void SetLoadedFailedStatus()
    {
      _frmMain.StatusText = Constants.StatusLoadedFailed;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set saved successfully status of Main form.
    /// </summary>
    public static void SetSavedStatus()
    {
      _frmMain.StatusText = Constants.StatusSaved;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set saving status of Main form.
    /// </summary>
    public static void SetSavingStatus()
    {
      _frmMain.StatusText = Constants.StatusSaving;
      _frmMain.Status = ApplicationStatus.Busy;
    }

    /// <summary>
    /// Set saved failed status of Main form.
    /// </summary>
    public static void SetSavedFailedStatus()
    {
      _frmMain.StatusText = Constants.StatusSavedFailed;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set deleted successfully status of Main form.
    /// </summary>
    public static void SetDeletedStatus()
    {
      _frmMain.StatusText = Constants.StatusDeleted;
      _frmMain.Status = ApplicationStatus.Done;
    }

    /// <summary>
    /// Set deleted failed status of Main form.
    /// </summary>
    public static void SetDeletedFailedStatus()
    {
      _frmMain.StatusText = Constants.StatusDeletedFailed;
      _frmMain.Status = ApplicationStatus.Done;
    }

    public static string GetTitle()
    {
      string title = String.Format("UBND TP.HCM - Uy Ban Phong Chong HIV/AIDS - Quan Ly Nguoi Benh HIV/AIDS (Build {0})", UIUtils.GetVersion());
      if (GlobalCache.Permission != null)
        title = String.Format("{0} - Đơn Vị: {1} | ", 
          GlobalCache.Permission.Username, 
          GlobalCache.Permission.UnitName) + title;

      return title;
    }
  }
}
